// * 路由查询

import { RouteObject } from "../types";

/**
 * 根据path查找对应的路由信息
 * @param path
 * @param routes
 * @returns
 */
export const searchRoute = (
  path: string,
  routes: RouteObject[] = []
): RouteObject => {
  let result: RouteObject = {};
  for (let item of routes) {
    if (item.path === path) return item;
    if (item.children) {
      const res = searchRoute(path, item.children);
      if (Object.keys(res).length) result = res;
    }
  }
  return result;
};
